package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.pojo.PageDTO;
import com.hmall.item.pojo.Result;
import com.hmall.item.service.IItemService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {
    @Override
    public PageDTO listAll(Integer page, Integer size) {
        IPage<Item> itemPage=new Page<>(page,size);
        LambdaQueryWrapper<Item> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(Item::getCreateTime);
        page(itemPage,queryWrapper);
        List<Item> records = itemPage.getRecords();
        long total = itemPage.getTotal();
        return new PageDTO<>(total,records);
    }
}
